﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using SolutionGenerator;

namespace BuiltDataTypeTemplate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //private List<SolutionConfigurationDataTypeTemplate> BuiltUI()
        //{
        //    List<SolutionConfigurationDataTypeTemplate> datas = new List<SolutionConfigurationDataTypeTemplate>();
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.BigInt,
        //        TemplateReplace = new List<string>(){ "<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\"></asp:TextBox>{IsRequired:0}",
        //            "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Binary,
        //        TemplateReplace = new List<string>() { "byte[]", "byte[]" }
        //    });
        //    SolutionConfigurationDataTypeTemplate template = new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Boolean,
        //        TemplateReplace = new List<string>(){"<asp:CheckBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" Checked=\"{DefaultValue}\" />",
        //        "<asp:CheckBox ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Enabled=\"false\" />"}
        //    };
        //    template.DefaultValueMap = new Dictionary<string, string>();
        //    template.DefaultValueMap.Add("((0))", "false");
        //    template.DefaultValueMap.Add("((1))", "true");
        //    datas.Add(template);
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.BSTR,
        //        TemplateReplace = new List<string>(){"<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" MaxLength=\"{ColumnLength}\"></asp:TextBox>{IsRequired:0}",
        //        "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Char,
        //        TemplateReplace = new List<string>(){"<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" MaxLength=\"{ColumnLength}\"></asp:TextBox>{IsRequired:0}",
        //        "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Currency,
        //        TemplateReplace = new List<string>() { "decimal", "decimal" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Date,
        //        TemplateReplace = new List<string>() { "DateTime", "DateTime" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.DBDate,
        //        TemplateReplace = new List<string>() { "DateTime", "DateTime" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.DBTime,
        //        TemplateReplace = new List<string>() { "TimeSpan", "TimeSpan" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.DBTimeStamp,
        //        TemplateReplace = new List<string>() { "DateTime", "DateTime" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Decimal,
        //        TemplateReplace = new List<string>() { "Decimal", "Decimal" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Double,
        //        TemplateReplace = new List<string>() { "Double", "Double" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Filetime,
        //        TemplateReplace = new List<string>() { "DateTime", "DateTime" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Guid,
        //        TemplateReplace = new List<string>() { "Guid", "Guid" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.IDispatch,
        //        TemplateReplace = new List<string>() { "object", "object" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Integer,
        //        TemplateReplace = new List<string>() { "<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\"></asp:TextBox>{IsRequired:0}",
        //            "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>",
        //            "<asp:DropDownList ID=\"{ForeignKeyParentTableName}{ColumnName}{ForeignKeyParentColumnName}Input\" runat=\"server\"></asp:DropDownList>"
        //        },
        //        TemplateIsRequired=new List<string>(){"<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.IUnknown,
        //        TemplateReplace = new List<string>() { "object", "object" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.LongVarBinary,
        //        TemplateReplace = new List<string>() { "byte[]", "byte[]" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.LongVarChar,
        //        TemplateReplace = new List<string>(){"<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" MaxLength=\"{ColumnLength}\"></asp:TextBox>{IsRequired:0}",
        //        "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.LongVarWChar,
        //        TemplateReplace = new List<string>(){"<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" MaxLength=\"{ColumnLength}\"></asp:TextBox>{IsRequired:0}",
        //        "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Numeric,
        //        TemplateReplace = new List<string>() { "Decimal", "Decimal" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.PropVariant,
        //        TemplateReplace = new List<string>() { "object", "object" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Single,
        //        TemplateReplace = new List<string>() { "Single", "Single" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.SmallInt,
        //        TemplateReplace = new List<string>() { "Int16", "Int16" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.TinyInt,
        //        TemplateReplace = new List<string>() { "SByte", "SByte" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.UnsignedBigInt,
        //        TemplateReplace = new List<string>() { "UInt64", "UInt64" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.UnsignedInt,
        //        TemplateReplace = new List<string>() { "UInt32", "UInt32" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.UnsignedSmallInt,
        //        TemplateReplace = new List<string>() { "UInt16", "UInt16" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.UnsignedTinyInt,
        //        TemplateReplace = new List<string>() { "Byte", "Byte" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.VarBinary,
        //        TemplateReplace = new List<string>() { "Byte[]", "Byte[]" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.VarChar,
        //        TemplateReplace = new List<string>() { "string", "string" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.Variant,
        //        TemplateReplace = new List<string>() { "object", "object" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.VarNumeric,
        //        TemplateReplace = new List<string>() { "decimal", "decimal" }
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.VarWChar,
        //        TemplateReplace = new List<string>(){"<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" MaxLength=\"{ColumnLength}\"></asp:TextBox>{IsRequired:0}",
        //        "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    datas.Add(new SolutionConfigurationDataTypeTemplate()
        //    {
        //        DataType = System.Data.OleDb.OleDbType.WChar,
        //        TemplateReplace = new List<string>(){"<asp:TextBox ID=\"{TableName}{ColumnName}Input\" runat=\"server\" MaxLength=\"{ColumnLength}\"></asp:TextBox>{IsRequired:0}",
        //        "<asp:Label ID=\"{TableName}{ColumnName}Display\" runat=\"server\" Text=\"\"></asp:Label>"},
        //        TemplateIsRequired = new List<string>(){ "<asp:RequiredFieldValidator ID=\"{TableName}{ColumnName}RequiredValidator\" runat=\"server\" ErrorMessage=\"This field is required\" ControlToValidate=\"{TableName}{ColumnName}Input\"></asp:RequiredFieldValidator>"}
        //    });
        //    return datas;
        //}
        private List<SolutionConfigurationDataTypeTemplate> BuiltLogic()
        {
            List<SolutionConfigurationDataTypeTemplate> datas = new List<SolutionConfigurationDataTypeTemplate>();
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.BigInt,
                TemplateReplace = new Dictionary<int, string>() { { 0, "int"} }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Binary,
                TemplateReplace = new Dictionary<int, string>() { { 0, "byte[]" } }
            });
            SolutionConfigurationDataTypeTemplate template = new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Boolean,
                TemplateReplace = new Dictionary<int, string>() { {0, "bool" } }
            };
            template.DefaultValueMap = new Dictionary<string, string>();
            template.DefaultValueMap.Add("((0))", "false");
            template.DefaultValueMap.Add("((1))", "true");
            datas.Add(template);
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.BSTR,
                TemplateReplace = new Dictionary<int, string>() { {0, "string" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Char,
                TemplateReplace = new Dictionary<int, string>() { {0, "string" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = (System.Data.OleDb.OleDbType)145,
                TemplateReplace = new Dictionary<int, string>() { { 0, "TimeSpan" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Currency,
                TemplateReplace = new Dictionary<int, string>() { {0, "decimal" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Date,
                TemplateReplace = new Dictionary<int, string>() { {0, "DateTime" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.DBDate,
                TemplateReplace = new Dictionary<int, string>() { {0, "DateTime" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.DBTime,
                TemplateReplace = new Dictionary<int, string>() { {0, "TimeSpan" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.DBTimeStamp,
                TemplateReplace = new Dictionary<int, string>() { {0, "DateTime" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Decimal,
                TemplateReplace = new Dictionary<int, string>() { {0, "Decimal"} }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Double,
                TemplateReplace = new Dictionary<int, string>() { {0,"Double"} }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Filetime,
                TemplateReplace = new Dictionary<int, string>() { {0,"DateTime"} }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Guid,
                TemplateReplace = new Dictionary<int, string>() { { 0, "Guid" } }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.IDispatch,
                TemplateReplace = new Dictionary<int,string>() { {0,"object" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Integer,
                TemplateReplace = new Dictionary<int, string>() { {0,"int"} }
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.IUnknown,
                TemplateReplace = new Dictionary<int,string>() { {0,"object" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.LongVarBinary,
                TemplateReplace = new Dictionary<int,string>() { {0,"byte[]" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.LongVarChar,
                TemplateReplace = new Dictionary<int,string>() { {0,"string" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.LongVarWChar,
                TemplateReplace = new Dictionary<int,string>() { {0,"string" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Numeric,
                TemplateReplace = new Dictionary<int,string>() { {0,"Decimal" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.PropVariant,
                TemplateReplace = new Dictionary<int,string>() { {0,"object" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Single,
                TemplateReplace = new Dictionary<int,string>() { {0,"Single" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.SmallInt,
                TemplateReplace = new Dictionary<int,string>() { {0,"Int16" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.TinyInt,
                TemplateReplace = new Dictionary<int,string>() { {0,"SByte" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.UnsignedBigInt,
                TemplateReplace = new Dictionary<int,string>() { {0,"UInt64" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.UnsignedInt,
                TemplateReplace = new Dictionary<int, string>() { {0,"UInt32" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.UnsignedSmallInt,
                TemplateReplace = new Dictionary<int, string>() { {0,"UInt16" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.UnsignedTinyInt,
                TemplateReplace = new Dictionary<int,string>() { {0,"Byte" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.VarBinary,
                TemplateReplace = new Dictionary<int,string>() { {0,"Byte[]" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.VarChar,
                TemplateReplace = new Dictionary<int,string>() { {0,"string" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.Variant,
                TemplateReplace = new Dictionary<int,string>() { {0,"object" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.VarNumeric,
                TemplateReplace = new Dictionary<int,string>() { {0,"decimal" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.VarWChar,
                TemplateReplace = new Dictionary<int,string>() { {0,"string" }}
            });
            datas.Add(new SolutionConfigurationDataTypeTemplate()
            {
                DataType = System.Data.OleDb.OleDbType.WChar,
                TemplateReplace = new Dictionary<int,string>() { {0,"string" }}
            });
            return datas;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.MaxLength = int.MaxValue;
            List<SolutionConfigurationDataTypeTemplate> datas = BuiltLogic();
            using (SerializeProcessing<List<SolutionConfigurationDataTypeTemplate>> serial =
                new SerializeProcessing<List<SolutionConfigurationDataTypeTemplate>>(datas))
                textBox1.Text = serial.Serialize;
        }
    }
}